package com.devops.admin.graphql;

import com.devops.admin.model.TableResult;
import com.devops.admin.model.ToolCategories;
import com.devops.admin.model.Tools;
import com.devops.admin.service.ToolCategoriesService;
import com.devops.admin.service.ToolsService;
import com.devops.admin.vo.DOSPageVo;
import com.devops.admin.vo.ToolCategoriesVo;
import com.devops.admin.vo.ToolsVo;
import com.devops.common.annotation.DOSLog;
import com.devops.constant.DevOpsConstant;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import org.apache.shiro.authz.annotation.RequiresPermissions;

import javax.annotation.Resource;

/**
 * @author jxt
 * @Notes
 * @date 2024/3/14 9:46
 */
@DgsComponent
public class DOSToolsFetcher {
    @Resource
    private ToolsService toolsService;

    @Resource
    private ToolCategoriesService toolCategoriesService;
    @DgsQuery
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public TableResult<ToolsVo> getTools(@InputArgument Tools tool, @InputArgument DOSPageVo pageVo) {
        return toolsService.queryTools(tool, pageVo);
    }

    @DgsMutation
    @DOSLog(description = "添加工具")
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public boolean addTool(@InputArgument Tools tool) {
        toolsService.addTool(tool);
        return true;
    }

    @DgsMutation
    @DOSLog(description = "更新工具")
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public boolean updateTool(@InputArgument Tools tool) {
        toolsService.updateTool(tool);
        return true;
    }

    @DgsMutation
    @DOSLog(description = "删除工具")
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public boolean deleteTool(@InputArgument Integer toolId) {
        toolsService.deleteTool(toolId);
        return true;
    }

    @DgsQuery
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public TableResult<ToolCategoriesVo> getToolCategories(@InputArgument DOSPageVo pageVo) {
        return toolCategoriesService.queryToolCategories(pageVo);
    }

    @DgsMutation
    @DOSLog(description = "添加工具分类")
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public boolean addToolCategory(@InputArgument ToolCategories toolCategory) {
        toolCategoriesService.addToolCategory(toolCategory);
        return true;
    }

    @DgsMutation
    @DOSLog(description = "修改工具分类")
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public boolean updateToolCategory(@InputArgument ToolCategories toolCategory) {
        toolCategoriesService.updateToolCategory(toolCategory);
        return true;
    }

    @DgsMutation
    @DOSLog(description = "删除工具分类")
    @RequiresPermissions(DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR)
    public boolean deleteToolCategory(@InputArgument Integer id) {
        toolCategoriesService.deleteToolCategory(id);
        return true;
    }
}
